package function.maker;

import function.maker.UnaryFunctionMaker;
import function.unary.UnaryFunction;

/**
 *
 * Fully Tested: No
 * Fully Documented: No
 * Created: 12-Apr-2012
 * Last Updated: 12-Apr-2012
 *
 * @author Shimu Wu
 */
public class MathFunctions extends UnaryFunctionMaker{

    /**
     * Returns a UnaryFunction, which contains an evaluate function that
     * returns the product of its argument and the given scalar.
     * 
     * @param scalar
     * @return 
     */
    public static UnaryFunction<Integer, Integer> multiplier(
            final Integer scalar) {
        return new UnaryFunction<Integer, Integer>() {

            public Integer evaluate(Integer arg) {
                return scalar * arg;
            }
        };
    }

    /**
     * Returns a UnaryFunction, which contains an evaluate function 
     * that returns its argument to the power of the given exponent. 
     * 
     * @param exponent
     * @return 
     */
    public static UnaryFunction<Integer, Integer> exponentiator(
            final Integer exponent) {
        return new UnaryFunction<Integer, Integer>() {
            public Integer evaluate(Integer arg) {
                return new Integer((int) Math.pow(arg, exponent));
            }
        };
    }
    
    /**
     * Returns a UnaryFunction, which contains an evaluate function
     * that returns the sum of its argument and the given value.
     * 
     * @param value
     * @return 
     */
    public static UnaryFunction<Integer, Integer> adder(
            final Integer value) {
        return new UnaryFunction<Integer, Integer>() {
            public Integer evaluate(Integer arg) {
                return arg + value;
            }
        };
    }
    
}
